package cn.stimd.spring.validation;

import cn.stimd.spring.beans.PropertyAccessException;

/**
 * Created by Stimd
 * 项目地址：https://gitee.com/stimd/spring-wheel
 * 公众号：Java编程探微
 */
public class DefaultBindingErrorProcessor implements BindingErrorProcessor{

    @Override
    public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
        String field = ex.getPropertyName();
        String code = ex.getErrorCode();
        Object rejectedValue = ex.getValue();

        bindingResult.addError(new FieldError(bindingResult.getObjectName(), field, rejectedValue, true, code, ex.getLocalizedMessage()));
    }
}
